package cn.agiledata.bank.common.service.email;

import java.util.Date;
import java.util.Map;

import cn.agiledata.bank.common.dao.ActionTypeTemplate;
import cn.agiledata.bank.common.service.NotifyMail;
import cn.agiledata.bank.common.util.DateUtil;
import cn.agiledata.bank.common.util.WeatherUtil;
import cn.agiledata.bank.hibernateBean.BankInfo;
import cn.agiledata.bank.hibernateBean.ScoresHis;
import cn.agiledata.bank.hibernateBean.SubAccount;
import cn.agiledata.bank.hibernateBean.Transaction;
import com.vnv.infrastructure.logic.IPBAppFactory;

public class GainMoneyEmail extends NotifyMail {
	
	private String paytype;
	

	public String getPaytype() {
		return paytype;
	}


	public void setPaytype(String paytype) {
		this.paytype = paytype;
	}
	
	private String mes;
	
	

	public String getMes() {
		return mes;
	}


	public void setMes(String mes) {
		this.mes = mes;
	}


	protected SubAccount setMailContext(Map vnvMap, Transaction tran,ScoresHis score) {
		SubAccount emailTo = tran.getDebit();
		String debitName = WeatherUtil.getNameOrEmailOrMobileByAccount(tran.getDebit().getAccount());
		String now = DateUtil.date2String(new Date());
		vnvMap.put("tranId", tran.getTransId());
		vnvMap.put("account",debitName);
		vnvMap.put("subaccount", tran.getDebit().getAccountName());
		vnvMap.put("banknumber", tran.getCardNo());
		ActionTypeTemplate at = (ActionTypeTemplate) IPBAppFactory.getObj("actionTypeTemplate");
		BankInfo bank = at.getBankInfoById(tran.getBankSeq().toString());
		String BankName = bank.getBankName();
		vnvMap.put("bank", BankName);
		vnvMap.put("tranTime",DateUtil.date2String(tran.getBeginDate()));
		vnvMap.put("amount", tran.getAmount().toString());
		vnvMap.put("fee", tran.getDebitFee().toString());
		double trueamount = tran.getAmount().doubleValue()-tran.getDebitFee().doubleValue();
		vnvMap.put("trueamount", new String(trueamount+""));
		String warn = "如果您无违反交易规则的行为，我们将在1-5个工作日内，将该款项汇到对应银行账户上，届时请查看您的银行账户。<br/>"+
		"----------------------------------------------- <br/>"+
		"特别提醒：<br/>"+
	"	在此期间，您账户中的该部分资金不能用于其他用途";

		vnvMap.put("warn", warn);
		vnvMap.put("paytype", getPaytype());
		String titlemessage = " 您于"+now+"进行了" + getContentTitle() +"操作：";
		vnvMap.put("titlemessage",titlemessage);
		vnvMap.put("time", now);
		vnvMap.put("mes", getMes());
		String cardNum;
        if(tran.getCardNo()!=null&&tran.getCardNo().length()>4)
        	cardNum = new StringBuffer(tran.getCardNo()).substring(tran.getCardNo().length()-4).toString();
        else 
        	cardNum = tran.getCardNo();
        vnvMap.put("cardNum", cardNum);
        if(cardNum == null) {
        	cardNum = "****";
        }
        vnvMap.put("banknumber", "********"+cardNum);
		return emailTo;
	}
}
